home *** CD-ROM | disk | FTP | other *** search
- package javax.swing.text;
-
- import java.io.IOException;
- import java.io.Writer;
- import java.util.Enumeration;
-
- public abstract class AbstractWriter {
- // $FF: renamed from: it javax.swing.text.ElementIterator
- private ElementIterator field_0;
- private Writer out;
- private int indentLevel;
- private int indentSpace;
- private Document doc;
- private int maxLineLength;
- private int currLength;
- private int startOffset;
- private int endOffset;
- private int offsetIndent;
- protected static final char NEWLINE = '\n';
-
- protected AbstractWriter(Writer var1, Document var2) {
- this(var1, (Document)var2, 0, var2.getLength());
- }
-
- protected AbstractWriter(Writer var1, Document var2, int var3, int var4) {
- this.indentLevel = 0;
- this.indentSpace = 2;
- this.doc = null;
- this.maxLineLength = 100;
- this.currLength = 0;
- this.startOffset = 0;
- this.endOffset = 0;
- this.offsetIndent = 0;
- this.doc = var2;
- this.field_0 = new ElementIterator(var2.getDefaultRootElement());
- this.out = var1;
- this.startOffset = var3;
- this.endOffset = var3 + var4;
- }
-
- protected AbstractWriter(Writer var1, Element var2) {
- this(var1, (Element)var2, 0, var2.getEndOffset());
- }
-
- protected AbstractWriter(Writer var1, Element var2, int var3, int var4) {
- this.indentLevel = 0;
- this.indentSpace = 2;
- this.doc = null;
- this.maxLineLength = 100;
- this.currLength = 0;
- this.startOffset = 0;
- this.endOffset = 0;
- this.offsetIndent = 0;
- this.doc = var2.getDocument();
- this.field_0 = new ElementIterator(var2);
- this.out = var1;
- this.startOffset = var3;
- this.endOffset = var3 + var4;
- }
-
- protected void decrIndent() {
- if (this.offsetIndent > 0) {
- --this.offsetIndent;
- } else {
- --this.indentLevel;
- }
-
- }
-
- protected Document getDocument() {
- return this.doc;
- }
-
- protected ElementIterator getElementIterator() {
- return this.field_0;
- }
-
- protected String getText(Element var1) throws BadLocationException {
- return this.doc.getText(var1.getStartOffset(), var1.getEndOffset() - var1.getStartOffset());
- }
-
- protected boolean inRange(Element var1) {
- return var1.getStartOffset() >= this.startOffset && var1.getStartOffset() < this.endOffset || this.startOffset >= var1.getStartOffset() && this.startOffset < var1.getEndOffset();
- }
-
- protected void incrIndent() {
- if (this.offsetIndent > 0) {
- ++this.offsetIndent;
- } else if (++this.indentLevel * this.indentSpace >= this.maxLineLength) {
- ++this.offsetIndent;
- --this.indentLevel;
- }
-
- }
-
- protected void indent() throws IOException {
- int var1 = this.indentLevel * this.indentSpace;
-
- for(int var2 = 0; var2 < var1; ++var2) {
- this.write(' ');
- }
-
- }
-
- protected void setIndentSpace(int var1) {
- this.indentSpace = var1;
- }
-
- protected void setLineLength(int var1) {
- this.maxLineLength = var1;
- }
-
- protected void text(Element var1) throws BadLocationException, IOException {
- String var2 = this.getText(var1);
- if (var2.length() > 0) {
- this.write(var2);
- }
-
- }
-
- protected abstract void write() throws IOException, BadLocationException;
-
- protected void write(char var1) throws IOException {
- this.out.write(var1);
- if (var1 == '\n') {
- this.currLength = 0;
- } else {
- ++this.currLength;
- if (this.currLength == this.maxLineLength) {
- this.out.write(10);
- this.currLength = 0;
- this.indent();
- }
- }
-
- }
-
- protected void write(String var1) throws IOException {
- int var2 = this.indentLevel * this.indentSpace;
- int var3 = var1.indexOf(10);
- if (this.currLength + var1.length() <= this.maxLineLength) {
- this.out.write(var1);
- this.currLength += var1.length();
- if (var3 >= 0) {
- this.currLength -= var3 - 1;
- }
- } else if (var2 + var1.length() <= this.maxLineLength) {
- this.out.write(10);
- this.currLength = 0;
- this.indent();
- this.out.write(var1);
- this.currLength = var2 + var1.length();
- if (var3 >= 0) {
- this.currLength -= var3 - 1;
- }
- } else {
- int var4 = this.maxLineLength - var2;
- String var5 = var1.substring(0, var4);
- this.write(var5);
- var5 = var1.substring(var4, var1.length());
- this.write(var5);
- }
-
- }
-
- protected void writeAttributes(AttributeSet var1) throws IOException {
- Enumeration var2 = var1.getAttributeNames();
-
- while(var2.hasMoreElements()) {
- Object var3 = var2.nextElement();
- this.write(" " + var3 + "=" + var1.getAttribute(var3));
- }
-
- }
- }
-